//package com.anmingle.pswb.filter;
//
//import com.alibaba.fastjson.JSONObject;
//import com.anmingle.common.R;
//import com.anmingle.common.ResponseResult;
//import com.anmingle.enums.ErrorCode;
//import jakarta.annotation.Resource;
//import jakarta.servlet.*;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.io.PrintWriter;
//
///**
// * @author 安明乐
// * @Title HandlerFilter
// * @Package IntelliJ IDEA
// * @date 2023/2/16 17:07
// */
//@Slf4j
////@Component
//public class HandlerFilter implements Filter {
//
//
//    @Value(value = "${key}")
//    private String key;
//
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        String gateway1 = request.getHeader("gateway");
//        //只要请求不经过网关就请求失败
//        if (!gateway1.equals(key)) {
//            log.info("越过网关访问用户{}", servletRequest.getLocalAddr());
//            ResponseResult<Object> error = R.error(40300, "unable to access");
//            String err = JSONObject.toJSONString(error);
//            PrintWriter writer = response.getWriter();
//            writer.write(err);
//            writer.close();
//            throw new RuntimeException("用户越过网关访问");
//        }
//
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//}
